<template>
  <div class="clearfix login">
    <div class="left pr">
      <router-link to="/" class="logo_login"></router-link>
      <div class="content_login">
        <div class="top clearfix">
          <span>账户密码登录</span>
          <router-link to="/dx_login">短信快捷登录></router-link>
        </div>
        <div class="bot">
          <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
            <el-form-item label="手机号或者邮箱登录" prop="name">
              <el-input v-model="ruleForm.name"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="pass">
              <el-input
                type="password"
                v-model="ruleForm.pass"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-button
              type="primary"
              class="button"
              @click="submitForm('ruleForm')"
              >提交</el-button
            >
          </el-form>
          <div class="clearfix forgot">
            <div class="fl">
              <router-link to="/forgetpas" class="zhmmdl"
                >忘记密码？</router-link
              >
            </div>
            <div class="fr">
              需要账户？
              <router-link to="/register" class="zhmmdl">创建账户</router-link>
            </div>
          </div>
          <div class="other_login" style="display: none">
            <div>
              <span>其他登录方式</span>
            </div>
            <div class="wechat">
              <div>
                <i class="iconfont icon-weixin"></i>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="right">
      <div class="img"></div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        name: "",
      },
      rules: {
        name: [
          { required: true, message: "请输入您的手机号或者邮箱号", trigger: "blur" },
          { min: 3,  message: "请输入正确的手机号或者邮箱号", trigger: "blur" },
        ],
        pass: [{ required: true, message: "密码不能为空", trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
       

        if (valid) {
          //定义一个json示例
          var jsons = {
            account: this.ruleForm.name,
            password: this.ruleForm.pass,
          };
          //在需要的事件中直接使用
          this.$axios
            .post(this.$api + "/api/user/login", jsons)
            .then((res) => {
              //console.log(res.data);
              if (res.data.code == 1) {
                ////console.log(res.data.data);
                // 登录成功
                // this.$message({
                //   message: '登陆成功',
                //   type: 'success'
                // });
                // 缓存token
                window.localStorage.setItem(
                  "token",
                  res.data.data.userinfo.token
                );
                window.localStorage.setItem(
                  "userid",
                  res.data.data.userinfo.user_id
                );

                // 跳转主页面
                this.$router.push("/#/dashboard");
              } else {
                this.$message.error(res.data.msg);
              }
            })
            .catch((Error) => {
              //console.log(Error);
            });

          //window.open("/#/index", "_self");
        } else {
          //console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    skip(url) {
      location.href = url;
    },
  },
  mounted() {
    this.token = window.localStorage.getItem("token")
      ? window.localStorage.getItem("token")
      : "";
    if (this.token) {
      location.href = "/#/dashboard";
    }
  },
};
</script>

<style scoped>
.el-form-item__label,
label {
  font-weight: normal !important;
}
.zhmmdl {
  color: #4285f4 !important;
}
label {
  font-weight: 500;
}
.el-form-item:first-child {
  margin-bottom: 10px;
}
.el-form-item__label,
label {
  font-weight: normal !important;
}
label {
  font-weight: 500;
}
html {
  height: 100% !important;
  overflow-y: hidden !important;
}
.wechat div {
  text-align: center;
}
.wechat div i {
  font-size: 1.25rem;
  color: #2f3e21;
}
.wechat div:hover {
  background: #5677fc;
}
.wechat div:hover i {
  color: #fff;
}
.login {
  width: 100vw;
  height: 100vh;
}
.login .left {
  width: 50%;
  float: left;
  padding: 3.125rem 3.75rem;
  height: 100vh;
}
.login .right {
  width: 50%;
  float: right;
}
.login .right .img {
  background: url(../../img/60.jpg) no-repeat;
  background-size: cover;
  width: 100%;
  height: 100vh;
}
.login .left .logo_login {
  background: url(../../img/logp.svg) no-repeat;
  width: 140px;
  height: 52px;
  display: block;
}
.content_login .top {
  font-size: 1.25rem;
  line-height: 1.875rem;
  color: #000000;
  margin-bottom: 0.9375rem;
}
.content_login .top a {
  font-size: 14px;
  color: #5677fc;
  float: right;
  cursor: pointer;
}
.content_login .top span:first-child {
  float: left;
}
.content_login {
  width: 18.75rem;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
input {
  border: 1px solid #c2cfe0;
  line-height: 2.5rem;
  padding: 0 1rem;
  border-radius: 5px;
  margin-bottom: 1.25rem;
  width: 100%;
  font-size: 12px;
  color: rgba(84, 85, 86, 0.8);
}
.button {
  width: 100%;
  line-height: 2.5rem;
  background: #5677fc;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  border: 1px solid #5677fc;
  border-radius: 5px;
  display: block;
  text-align: center;
  padding: 0;
}
.button:hover {
  background: #fff !important;
  color: #5677fc;
  border-color: #5677fc;
}
.forgot {
  font-size: 0.875rem;
  line-height: 3.75rem;
  color: #5677fc;
  cursor: pointer;
}
.forgot .fr {
  color: #686868;
}
.forgot .fr span {
  color: #5677fc;
}
.other_login > div:nth-child(1) span {
  position: relative;
  background: #fff;
  position: relative;
  z-index: 10;
}
.other_login > div:nth-child(1) {
  background: #fff;
  text-align: center;

  font-size: 0.875rem;
  line-height: 2.5rem;
  color: #686868;
  position: relative;
  text-align: center;
}
.other_login > div:nth-child(1)::before {
  content: "";
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 100%;
  height: 1px;
  background: #c2cfe0;
  left: 0;
  z-index: 9;
}
.wechat div {
  width: 2rem;
  height: 2rem;

  border-radius: 50%;
  line-height: 2rem;
  margin: 0 auto;
  border: 1px solid #c2cfe0;
}
@media (max-width: 990px) {
  .login .right,
  .login .left {
    width: 100%;
  }.login .left  {
    background: #f5f5f5;
  }
  .login .right {
    display: none;
  }
}
@media (max-width: 500px) {
   .login .left {
     padding: 20px;
   }
   .content_login {
     width: 80%;
   }
}
</style>
